Random variables overview

You can create random numeric and text (string) variables in the variable definitions table below the Description.  

After clicking add varDefinition, click add @varType to indicate the Type as numeric or string, and provide variable specifics.

The following table provides basic information pertaining to:

All variables (text and numeric)

Names must be unique within each item, should be logical (for example, m for mass), and can not include:

  • Characters that could be interpreted as a function – vardef sink could be read as sin(k).
  • Primes, such as f' or S'.

You must define variables in the variable table before you can use them in item elements, or in other variables that depend on them. For instance, if the third variable in the table is coded using m*v, you must define m and v as the first two variables in the table.

You can insert variables using the var tag in introductions, tag lines, Parts, Hints, transitions, answer boxes (correct and incorrect answers), and follow-up text. For information on using variables in answer boxes, see Using variables with answer types. Variable names and initialization rules display at the top of the Solution View.

Numeric variables

Must be numeric values, or expressions representing numeric values.

Can be used in calculations.

Are defined either by:

  • Min/Max/Step values that specify the lower and upper boundaries, and the increment between values. For example, you can create a randomized variable for any integer value between 10 and 50, Min=10, Max=50, and Step=1 that would include values of 10, 11, 12, … 48, 49, 50. Min/Max/Step values can be constants or formulas that use previously defined variables. To define a constant, use the same value for Min and Max, and specify Step as 0. Most of the time, you'll define numeric variables with Min/Max/Step.
  • A Value List to designate a set of numerical values, for example, to associate a compound to its weight, or to include a series of prime numbers (3, 5, 7, 11, and so on). See Value Lists for an example.

Can include:

  • Units – Use TeX coding; the Item Editor renders units in Roman typeface by default, so you don't have to enter \rm.
  • Conversion factor – Converts the numeric value you enter to another system of units when calculating the answer.
  • LaTeX – Determines how the numeric variable name displays to students. This setting overrides the default rendering, which is usually adequate.
  • Format values – Specifies the format of the displayed numerical value, for example, the number of digits displayed or whether a value displays in scientific notation.
Text variables

Must be valid HTML text.

Can include img, var, and TeX formatting tags for display.

Consist of a series of words or letters you enter called a Value Lists. The system randomly displays one value from each list every time a student views the item. Useful for chemical formulas, as well as for linking text and numeric values.

 

Value Lists

For text variables, the Mastering system doesn't generate random values as it does for numeric variables when you enter Min/Max/Step values. Instead, you enter a set of words or letters, called a Value List, for each text variable. The system randomly displays one of the values in the list each time a student views the item.

You must supply a numeric ID for each Value List. To associate lists with related values, use the same ID. This is useful to:

Associating text with a numeric

The example below associates the four elements (bromine, aluminum, calcium, and sodium) with their respective atomic weights by assigning an ID of 2 to both lists. To correctly associate values, code each value set in the same order in each list (values in the first cell of each list are associated, values in the second cell of each list are associated, and so on).

Displaying a variable differently, depending on its location

You may want to include the same variable in a Part (using TeX) and in a solutionChemicalFormula answer (using Chem TeX, required). To do this, define each variable separately, but enter the same ID for both. In the following example, whenever the system randomly chooses Na^+, it uses Na{^{+}} for the answer.

Note: If you temporarily turn off randomization to check your work (Action > Standard View Non-Randomized or Action > Solution View Non-Randomized), only the first value in each list displays wherever the variable appears in the item.

 

Using variables with answer types

You can add variables to answer boxes, as described in this section.

Numeric variables

You can use numeric variables for the same answer types as text variables However, most of the time you'll add numeric variables to solutionSymbolic and solutionSymbolicSet answer boxes. Do not use colons before or after the variable.

Text variables

You can add text variables to answer boxes for the following answer types:

Answer types Requirements

solutionMultipleChoiceRadio

solutionMultipleChoiceDropdown

solutionMultipleChoiceSelect

Code answers using the var tag. Make sure that each correct answer iteration has the same ID and Option. You can’t randomize which choice is correct, only which values display.

solutionSymbolic

solutionSymbolicSet

You can only enter one text variable per answer. Don’t enter colons before or after text or numeric variables. Colons are required only for chemical formula and text answer types. See Formatting for solutionChemicalFormula and solutionString Answer Types.

solutionString

solutionStringSet

Code answers using unformatted text (no TeX or html formatting). Use colons before and after each variable.

solutionChemical

solutionChemicalSet

Code answers with text variables using Chem TeX. Use colons before and after each variable.

solutionAppletRanking

solutionAppletSorting

solutionAppletVocabulary

solutionAppletLabel

Code answers using the var tag. You can use unformatted text (no TeX or html formatting). For ranking and sorting, you can include images in the Value List and code them using a var tag and htmlText.

For each correct answer variation, be aware that you can't randomize which choice is correct, only which values display. For example, for every variation of a vocabulary task, the same text variable appears in the same place. Each value for the variable must be correct within the sentence. See the following section for a sorting example.

 

Sorting example

Note that the Item IDs for the variables:

Match the Bin IDs for the correct elements. When coding, you must ensure that the Value List for each category contains every item for that category. In this example, the Value List for:

as shown below.

Formatting for solutionChemicalFormula and solutionString Answer Types

Use a colon before and after both numeric and text variables in all solutionChemicalFormula and solutionString answer types. For example, code the variable F_2 in the solutionChemicalFormula answer type as:

For symbolic answer types, colons aren't needed.

 

See also:

Defining random variables

Defining randomized variables with other variables

Functions for specifying randomly generated values

Formatting variables